home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / ixemul-complete / ixemul / library / ixemul.h < prev    next >
C/C++ Source or Header  |  1996-08-13  |  9KB  |  340 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  ixemul.h,v 1.1.1.1 1994/04/04 04:29:38 amiga Exp
  20.  *
  21.  *  ixemul.h,v
  22.  * Revision 1.1.1.1  1994/04/04  04:29:38  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.4  1993/11/05  22:14:40  mwild
  26.  *  changes there, here...
  27.  *
  28.  *  Revision 1.3  1992/10/20  16:32:33  mwild
  29.  *  *** empty log message ***
  30.  *
  31.  *  Revision 1.2  1992/07/04  19:25:26  mwild
  32.  *  change __rwport to reflect the current state of the (now global) async port
  33.  *
  34.  * Revision 1.1  1992/05/14  20:36:14  mwild
  35.  * Initial revision
  36.  *
  37.  */
  38.  
  39. #ifndef _IXEMUL_H_
  40. #define _IXEMUL_H_
  41.  
  42. #ifdef START
  43.  
  44. /* definitions for the assembler startup file */
  45.  
  46. /* when I've REALLY lots of free time, I'll rewrite header files, but now... */
  47.  
  48. /* amazingly works, contains only defines ;-)) */
  49. #include <exec/alerts.h>
  50.  
  51. #define _LVOOpenLibrary        -0x228
  52. #define _LVOCloseLibrary     -0x19e
  53. #define _LVOAlert        -0x6c
  54. #define _LVOFreeMem        -0xd2
  55. #define _LVORemove        -0xfc
  56.  
  57. #define RTC_MATCHWORD    0x4afc
  58. #define RTF_AUTOINIT    (1<<7)
  59.  
  60. #define LIBF_CHANGED    (1<<1)
  61. #define LIBF_SUMUSED    (1<<2)
  62. /* seems there is an assembler bug in expression evaluation here.. */
  63. #define LIBF_CHANGED_SUMUSED 0x6
  64. #define LIBF_DELEXP    (1<<3)
  65. #define LIBB_DELEXP    3
  66.  
  67. #define LN_TYPE        8
  68. #define LN_NAME        10
  69. #define NT_LIBRARY    9
  70. #define MP_FLAGS    14
  71. #define PA_IGNORE    2
  72.  
  73. #define LIST_SIZEOF    14
  74.  
  75. #define THISTASK    276
  76.  
  77. #define INITBYTE(field,val)    .word 0xe000; .word (field); .byte (val); .byte 0
  78. #define INITWORD(field,val)    .word 0xd000; .word (field); .word (val)
  79. #define INITLONG(field,val)    .word 0xc000; .word (field); .long (val)
  80.  
  81. /*
  82.  * our library base.. 
  83.  */
  84.  
  85. /* struct library */
  86. #define    IXBASE_NODE    0
  87. #define IXBASE_FLAGS    14
  88. #define IXBASE_NEGSIZE    16
  89. #define IXBASE_POSSIZE    18
  90. #define IXBASE_VERSION    20
  91. #define IXBASE_REVISION    22
  92. #define IXBASE_IDSTRING    24
  93. #define IXBASE_SUM    28
  94. #define IXBASE_OPENCNT    32
  95. #define IXBASE_LIBRARY    34    /* size of library */
  96.  
  97. /* custom part */
  98. #define IXBASE_MYFLAGS        (IXBASE_LIBRARY + 0)
  99. #define IXBASE_SEGLIST        (IXBASE_MYFLAGS + 2)
  100. #define IXBASE_C_PRIVATE    (IXBASE_SEGLIST + 4)
  101.  
  102. #else  /* C-part */
  103.  
  104. #include <exec/types.h>
  105. #include <exec/libraries.h>
  106. #include <exec/execbase.h>
  107. #include <exec/ports.h>
  108. #include <libraries/dosextens.h>
  109. #include <dos/notify.h>
  110.  
  111. #include <sys/types.h>
  112.  
  113. #ifdef _KERNEL
  114. #define _INTERNAL_FILE
  115. #endif
  116.  
  117. #include <sys/file.h>
  118. #include <sys/param.h>
  119. #include <packets.h>
  120. #include <sys/syscall.h>
  121. #include <sys/ixnet_syscall.h>
  122. #include <signal.h>
  123. #include <user.h>
  124.  
  125. #include <errno.h>
  126.  
  127. /* ix_flags defines */
  128.  
  129.    #define ix_profile_method_mask             0x0000C000
  130.    #define ix_create_enforcer_hit             0x00002000
  131.    #define ix_do_not_flush_library             0x00001000
  132.    #define ix_allow_amiga_wildcard             0x00000800
  133.    #define ix_no_insert_disk_requester             0x00000400
  134.    #define ix_unix_pattern_matching_case_sensitive    0x00000200
  135. /* #define ix_unix_pattern_matching             0x00000100 obsolete */
  136. /* #define ix_no_ces_then_open_console             0x00000080 obsolete */
  137.    #define ix_ignore_global_env             0x00000040
  138. /* #define ix_disable_fibcache                 0x00000020 obsolete */
  139. /* #define ix_translate_dots                 0x00000010 obsolete */
  140.    #define ix_watch_stack                 0x00000008
  141. /* #define ix_force_translation             0x00000004 obsolete */
  142. /* #define ix_translate_symlinks             0x00000002 obsolete */
  143.    #define ix_translate_slash                0x00000001
  144.  
  145. /* ix_profile_method defines */
  146.  
  147. /* only if the pc is in the program is a hit recorded */
  148. #define IX_PROFILE_PROGRAM     0x00000000
  149.  
  150. /* while the task is running, the last function in your program that was
  151.    entered records a hit */
  152. #define IX_PROFILE_TASK     0x00004000
  153.  
  154. /* always record a hit (again the last function that was entered), even
  155.    if another task is running */
  156. #define IX_PROFILE_ALWAYS    0x00008000
  157.  
  158. /* not used */
  159. #define IX_PROFILE_UNUSED    0x0000C000
  160.  
  161.  
  162. /* ix_network_type enum */
  163.  
  164. enum
  165. {
  166.   IX_NETWORK_AUTO,
  167.   IX_NETWORK_NONE,
  168.   IX_NETWORK_AS225,
  169.   IX_NETWORK_AMITCP,
  170.   IX_NETWORK_END_OF_ENUM
  171. };
  172.  
  173. /* configure this to the number of hash queues you like, 
  174.  * use a prime number !!
  175.  */
  176. #define IX_NUM_SLEEP_QUEUES    31
  177.  
  178. /* the number of available ptys ( '/dev/pty[p-u][0-9a-f]' ) */
  179. #define IX_NUM_PTYS        (6 * 16)
  180.  
  181. #define IX_PTY_SLAVE        0x03  /* 0011 */
  182. #define IX_PTY_MASTER        0x0c  /* 1100 */
  183.  
  184. #define IX_PTY_OPEN        0x05  /* 0101 */
  185. #define IX_PTY_CLOSE        0x0a  /* 1010 */
  186.  
  187. struct ixemul_base {
  188.   struct Library        ix_lib;
  189.  
  190. /* don't use the remainder of the library base. The contents can change
  191.    without warning in the future. */
  192. #ifdef _KERNEL
  193.   unsigned char            ix_myflags;    /* used by start.s */
  194.   unsigned char            ix_pad;
  195.   BPTR                ix_seg_list;    /* used by start.s */
  196.  
  197.   /* the global file table with current size */
  198.   struct file            *ix_file_tab;
  199.   struct file            *ix_fileNFILE;
  200.   struct file            *ix_lastf;
  201.  
  202.   /* size of start of red zone from bottom of stack */
  203.   int                ix_red_zone_size;
  204.  
  205.   struct SignalSemaphore    ix_semaph;
  206.   int                ix_membuf_limit;
  207.   
  208.   /* multiplier for id_BytesPerBlock to get to st_blksize, default 64 */
  209.   int                ix_fs_buf_factor;
  210.  
  211.   unsigned long            ix_flags;
  212.  
  213.   struct MinList        ix_sleep_queues [IX_NUM_SLEEP_QUEUES];
  214.  
  215.   struct MinList        ix_socket_list;
  216.   long                      ix_gmt_offset;
  217.   int                ix_network_type;
  218.  
  219.   int                ix_next_free_port;
  220.   struct Task                  *ix_task_switcher;
  221.   char                      **ix_global_environment;
  222.   struct NotifyRequest          ix_notify_request;
  223.   char                ix_ptys[IX_NUM_PTYS];
  224. #endif
  225. };
  226.  
  227. #define syscall(vec, args...) \
  228.   ({register int (*_sc)()=(void *)(&((char *)ixemulbase)[-((vec)+4)*6]); _sc(args);})
  229.  
  230. #define netcall(vec, args...) \
  231.   ({register int (*_sc)()=(void *)(&((char *)u.u_ixnetbase)[-((vec)+4)*6]); _sc(args);})
  232.  
  233. /* Structure to pass ixemul.library settings to/from the library base */
  234. struct ix_settings {
  235.   int version;
  236.   int revision;
  237.   unsigned long flags;
  238.   int membuf_limit;
  239.   int red_zone_size;
  240.   int fs_buf_factor;
  241.   int network_type;
  242. };
  243.  
  244. /* structure to keep track of the current SegList */
  245. struct my_seg {
  246.   BPTR    segment;    /* the thing our clients can use */
  247.   enum { LOADSEG, RESSEG } type;
  248.   char  *name;        /* name of the executable */
  249.   u_int    priv;        /* information depending on type */
  250. };
  251.  
  252. /* Environment name of ixemul settings */
  253. #define IX_ENV_SETTINGS "ixemul.prefs"
  254.  
  255. void ix_set_gmt_offset(long offset);
  256. long ix_get_gmt_offset(void);
  257. struct ix_settings *ix_get_default_settings(void);
  258. struct ix_settings *ix_get_settings(void);
  259. void ix_set_settings(struct ix_settings *settings);
  260.  
  261. #ifdef _KERNEL
  262.  
  263. #include <ixprotos.h>
  264.  
  265. extern struct ixemul_base *ixemulbase;
  266.  
  267. #define ix          (*ixemulbase)
  268. #define u          (*(struct user *)(SysBase->ThisTask->tc_TrapData))
  269. #define getuser(p)      ((struct user *)((p)->pr_Task.tc_TrapData))
  270. #define betterthan68000() (SysBase->AttnFlags & (AFF_68010 | AFF_68020 | AFF_68030 | AFF_68040))
  271. #define betterthan68010() (SysBase->AttnFlags & (AFF_68020 | AFF_68030 | AFF_68040))
  272. #define gotanfpu()      (SysBase->AttnFlags & (AFF_68881 | AFF_68882))
  273.  
  274. static inline u_int get_usp (void) 
  275.   u_int res;
  276.  
  277.   asm volatile ("movel    usp,%0" : "=a" (res));
  278.   return res;
  279. }
  280.  
  281. static inline void set_usp (u_int new_usp)
  282. {
  283.   asm volatile ("movel  %0,usp" : /* no output */ : "a" (new_usp));
  284. }
  285.  
  286. static inline u_int get_sp (void) 
  287.   u_int res;
  288.  
  289.   asm volatile ("movel    sp,%0" : "=a" (res));
  290.   return res;
  291. }
  292.  
  293. static inline void set_sp (u_int new_sp)
  294. {
  295.   asm volatile ("movel  %0,sp" : /* no output */ : "a" (new_sp));
  296. }
  297.  
  298. static inline u_short get_sr (void) 
  299.   u_short res;
  300.  
  301.   asm volatile ("movew    sr,%0" : "=g" (res));
  302.   return res;
  303. }
  304.  
  305. static inline u_int get_fp (void) 
  306.   u_int res;
  307.  
  308.   asm volatile ("movel    a5,%0" : "=g" (res));
  309.   return res;
  310. }
  311.  
  312. #define PRIVATE
  313. extern struct ExecBase *SysBase;
  314. #include <inline/exec.h>
  315. #undef PRIVATE
  316.  
  317. extern struct Library *muBase;
  318. /* Multiuser inlines */
  319. #include "multiuser_inlines.h"
  320.  
  321. extern struct DosLibrary *DOSBase;
  322. #include <inline/dos.h>
  323.  
  324. #include <inline/alib.h>
  325.  
  326. #define errno (* u.u_errno)
  327.  
  328. #define __srwport (u.u_sync_mp)
  329. #define __selport (u.u_select_mp)
  330.  
  331. #endif /* _KERNEL */
  332.  
  333. #endif /* START */
  334.  
  335. #endif /* _IXEMUL_H */
  336.